package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.dto.sys.SysUserDto;
import com.atguigu.spzx.model.entity.sys.SysUser;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * title:
 * author: zgl
 * date: 2023/12/28
 * description：
 */
@RestController
@RequestMapping("/admin/system/user")
@Tag(name = "用户管理模块")
//@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true", allowedHeaders = {"*"})
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    //分页查询数据
    @GetMapping("/getUserList/{pageNum}/{pageSize}")
    @Operation(summary = "查询用户列表接口")
    public Result getUserList(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize,
            SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo = sysUserService.getUserList(pageNum, pageSize, sysUserDto);
        return Result.ok(pageInfo);
    }

    //删除用户
        @DeleteMapping("/deleteById/{id}")
        @Operation(summary = "删除用户接口")
    public Result deleteById(@PathVariable Long id) {
        sysUserService.deleteById(id);
        return Result.ok();
    }

    //添加用户
    @PostMapping("/saveUser")
    @Operation(summary = "添加用户接口")
    public Result saveUser(@RequestBody SysUser sysUser) {
        sysUserService.saveUser(sysUser);
        return Result.ok();
    }

    //修改用户
    @PutMapping("/updateUser")
    @Operation(summary = "修改用户接口")
    public Result updateUser(@RequestBody SysUser sysUser) {
        System.out.println(sysUser);
        sysUserService.updateUser(sysUser);
        return Result.ok();
    }
    //查询用户根据id
    @GetMapping("/getUser/{id}")
    @Operation(summary = "id查询用户接口")
    public Result getUserById(@PathVariable Long id) {
        SysUser sysUser = sysUserService.getUserById(id);
        return Result.ok(sysUser);
    }

}
